package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.SetmealService;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api("套菜相关接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    /*
    * 新增菜品
    * */
    @PostMapping()
    @ApiOperation("新增套餐")
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO) {
        log.info("新增套餐,产品信息：{}", setmealDTO);
        setmealService.add(setmealDTO);
        return Result.success();
    }
    /*
    * 菜品分页查询
    * */
    @GetMapping("/page")
    @ApiOperation("套餐分页查询")
    public Result<PageResult> ListSetmeal(SetmealPageQueryDTO queryDTO) {
        log.info("开启套餐分页查询,参数：{}", queryDTO);
        PageResult list= setmealService.query(queryDTO);
        return Result.success(list);
    }
    /*
    * 批量删除
    * */
    @DeleteMapping
    @ApiOperation("批量删除套餐")
    public Result deleteDish(@RequestParam List<Long> ids) {
        setmealService.del(ids);
        return Result.success();
    }
    /*
    * 根据id获取菜品信息
    * */
    @GetMapping("/{id}")
    @ApiOperation("根据id获取套餐信息")
    public Result<SetmealVO> getById(@PathVariable("id") Long id) {
        SetmealVO setmealVO= setmealService.getById(id);
        return Result.success(setmealVO);
    }
    /*
    * 启用/禁用菜品
    * */
    @PostMapping("/status/{status}")
    @ApiOperation("启用/禁用套餐")
    public Result updateStatus(@RequestParam(name = "id") Long id,@PathVariable("status") Integer status) {
        log.info("禁用/启用菜品,菜品id：{}，当前菜品状态，{}", id,status);
        setmealService.updateStatus(id,status);
        return Result.success();
    }
    /*
    * 修改菜品信息
    * */
    @PutMapping()
    @ApiOperation("修改套餐信息")
    public Result updateDish(@RequestBody SetmealDTO setmealDTO) {
        setmealService.update(setmealDTO);
        return Result.success();
    }
//    /*
//    * 获取菜品分类下的菜品集合
//    * */
//    @GetMapping("/list")
//    @ApiOperation("根据分类Id获取菜品集合")
//    public Result<List<Dish>> listDish(@RequestParam(name = "categoryId") Long categoryId) {
//        List<Dish>  list=dishService.listByCatehoryId(categoryId);
//        return Result.success(list);
//    }

}
